package com.hongye.area.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hongye.area.entity.MetroEntity;
import com.hongye.area.service.MetroService;
import com.zxy.common.utils.PageUtils;
import com.zxy.common.utils.R;



/**
 * 
 *
 * @author cyj
 * @email sunlightcs@gmail.com
 * @date 2022-04-22 16:19:01
 */
@RestController
@RequestMapping("area/metro")
public class MetroController {
    @Autowired
    private MetroService metroService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params,@RequestBody MetroEntity metroEntity){
        PageUtils page = metroService.queryPage(params,metroEntity);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{mid}")
    public R info(@PathVariable("mid") Long mid){
		MetroEntity metro = metroService.getById(mid);

        return R.ok().put("metro", metro);
    }

    /**
     * 添加地铁线路
     */
    @RequestMapping("/save")
    public R save(@RequestBody MetroEntity metro){
        metro.setState(1);
		metroService.save(metro);

        return R.ok("添加成功");
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MetroEntity metro){
		metroService.updateById(metro);

        return R.ok("修改成功");
    }
    //修改状态
    @RequestMapping("/{id}/updateState/{state}")
    public R updateState(@PathVariable("id")Integer id,@PathVariable("state")Integer state) {
        metroService.updateState(id,state);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] mids){
		metroService.removeByIds(Arrays.asList(mids));

        return R.ok();
    }

}
